﻿namespace ET.Client
{
	[Event(SceneType.Demo)]
	public class AppStartInitFinish_CreateLoginUI: AEvent<Scene, AppStartInitFinish>
	{
		protected override async ETTask Run(Scene root, AppStartInitFinish args)
		{
			await UIHelper.Create(root, UIType.UILogin, UILayer.Mid);
			
			// 异步调用
			TestAsync(root).Coroutine();
			TestAsync2(root).Coroutine();

			//异步等待调用
			Log.Debug("start Test!");
			await TestAsync(root);
			int testValue = await this.TestAsync2(root);
			Log.Debug($"test value: {testValue}");
			Log.Debug("Finish Test! ");

			// computer的创建和日志的输出学习
			// Computer computer = root.GetComponent<ComputersComponent>().AddChild<Computer>();
			//
			// computer.AddComponent<PCCaseComponent>();
			// computer.AddComponent<MonitorComponent,int>(10);
			//
			// computer.open();
			//
			// computer.GetComponent<MonitorComponent>().ChangeBrightness(5);
			//
			// await root.GetComponent<TimerComponent>().WaitAsync(3000);
			//
			// Scene scene = computer.Root();
			//
			// Log.Debug($"root instanceId:{root.InstanceId} scene instanceId:{scene.InstanceId}");
			// computer?.Dispose();
		}

		public async ETTask TestAsync(Scene root)
		{
			Log.Debug("Enter TestAsync");
			await root.GetComponent<TimerComponent>().WaitAsync(3000);
			Log.Debug("Exit TestAsync");
		}
		
		public async ETTask<int> TestAsync2(Scene root)
		{
			Log.Debug("Enter TestAsync2");
			await root.GetComponent<TimerComponent>().WaitAsync(3000);
			Log.Debug("Exit TestAsync2");
			return 10;
		}
		
	}
}
